package com.jason.kotlin.gank.ui.section

import android.content.Context
import com.jason.kotlin.gank.R
import com.jason.kotlin.gank.model.GankBannerBean
import com.jason.kotlin.gank.ui.adapter.ImageNetAdapter
import com.jason.library.common.base.IViewSection
import com.youth.banner.Banner
import com.youth.banner.indicator.RectangleIndicator
import com.youth.banner.util.BannerUtils

class GankHomeBannerSection(context: Context) :
    IViewSection<List<GankBannerBean>>(context) {

    private lateinit var banner: Banner<Any, ImageNetAdapter>

    private lateinit var bannerAdapter: ImageNetAdapter

    override fun populateView() {
        banner = rootView.findViewById(R.id.banner)
        bannerAdapter = ImageNetAdapter()
        banner.indicator = RectangleIndicator(context)
        banner.setIndicatorSpace(BannerUtils.dp2px(4f).toInt())
        banner.setIndicatorRadius(0)
        banner.apply {
            adapter = bannerAdapter
        }
    }

    override fun getLayoutId() = R.layout.gank_banner_layout


    override fun setData(data: List<GankBannerBean>) {
        bannerAdapter.setDatas(data)
        bannerAdapter.notifyDataSetChanged()
    }

    override fun onStart() {
        banner.start()
    }

    override fun onStop() {
        banner.stop()
    }
}